<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;
use app\admin\model\AuthRule;

class Hsmenu extends AdminBase
{
    protected function _initialize()
    {
        parent::_initialize();
        $this->assign('admin_menu_level_list', AuthRule::getAll());
    }

    public function index()
    {
        return $this->fetch('index');
    }

    public function edit()
    {
        return $this->fetch('edit', ['admin_menu' => AuthRule::get(input('id/d')),'pid' => input('pid/d')]);
    }

    /**
     * 保存菜单
     */
    public function save()
    {
        if ($this->request->isAjax()) {
            $m = new AuthRule;
            return $m->_save();
        }
    }

    public function setStatus($id)
    {
        if ($this->request->isAjax()) {
            $m = new AuthRule;
            if ($m->allowField('status,sort')->save(input('post.'),['id'=>$id]) !== false) {
                $this->success('更新成功');
            } else {
                $this->error($m->getError());
            }
        }
    }

    public function delete($id)
    {
        if ($this->request->isAjax()) {
            $m = new AuthRule;
            return $m->_delete($id);
        }
    }
}